package com.jwthhealth_pub.wristband.setting.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialog;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.base.BaseActivity;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.weigan.loopview.LoopView;
import com.weigan.loopview.OnItemSelectedListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 手环 设置健康目标
 * Created by liuzhen on 2017/12/20.
 */

public class WristBandSettingHealthTargetActivity extends BaseActivity {

    @BindView(R.id.btn_guide_target_step)
    TextView btnGuideTargetStep;
    @BindView(R.id.title_layout)
    TitleLayout titleLayout;
    private List<String> targetParameList;
    private String mTargetSetp;

    @Override
    protected void title() {
        titleLayout.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wristband_healthtarget);
        ButterKnife.bind(this);
    }

    private void showTarget() {
        targetParameList = new ArrayList<>();

        for (int i=0; i<20; i++) {
            targetParameList.add((5000+1000*i)+"");
        }

        final BottomSheetDialog shopbottomSheetDialog = new BottomSheetDialog(this);
        View view = View.inflate(this, R.layout.item_guide_target_step, null);
        shopbottomSheetDialog.setContentView(view);
        TextView completeBtn = view.findViewById(R.id.tv_complete);
        ImageView closeBtn = view.findViewById(R.id.btn_close);

        LoopView loopView = view.findViewById(R.id.loopView);
        loopView.setNotLoop();
        loopView.setItems(targetParameList);
        loopView.setInitPosition(20);

        String origanlStep = targetParameList.get(19);
        if (origanlStep != null) {
            mTargetSetp = origanlStep;
        }

        loopView.setListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(int index) {
                mTargetSetp = targetParameList.get(index);
            }
        });

        completeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //已经选择步数
                btnGuideTargetStep.setText(mTargetSetp);
                shopbottomSheetDialog.dismiss();
            }
        });

        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shopbottomSheetDialog.dismiss();
            }
        });

        shopbottomSheetDialog.show();
    }

    @OnClick(R.id.layout_targetstep)
    public void onViewClicked() {
        showTarget();
    }
}
